package org.footballmanager.pandafootball.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.common.annotation.SystemServiceLog;
import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.dao.FootTeamDao;
import org.footballmanager.pandafootball.system.domain.*;
import org.footballmanager.pandafootball.system.form.impl.FootTeamSearchForm;
import org.footballmanager.pandafootball.system.mapper.FootTeamMapper;
import org.footballmanager.pandafootball.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@Service("footTeamService")
public class FootTeamServiceImpl extends ServiceImpl<FootTeam> implements FootTeamService {
    //初始资金是多少
    public static final double CSZJ = 100D;
    private List<FootClub> alllist = new ArrayList<>();
    private List<FootClub> temp = new ArrayList<>();

    @Autowired
    private FootTeamDao footTeamDao;
    @Autowired
    private FootTeamMapper footTeamMapper;
    @Autowired
    private FootUserService footUserService;
    @Autowired
    private FootUserPersonService footUserPersonService;
    @Autowired
    private FootClubService footClubService;
    @Autowired
    private FootRankService footRankService;
    @Autowired
    private FootChipService footChipService;
    @Autowired
    private FootZnxService footZnxService;
    @Autowired
    private FootZjService footZjService;
    @Autowired
    private FootQdService footQdService;

    /**
     * 更新非空字段
     *
     * @param entity  参数
     * @param request 参数
     * @return 返回值
     */
    @Override
    @Transactional
    @SystemServiceLog(description = "更新非空字段")
    public int updateNotNull(FootTeam entity, HttpServletRequest request) {
        FootTeam team = this.get(entity.getId());
        if (team != null) {
            Double bgje = team.getQdZzj() - entity.getQdZzj();
            footZjService.sendZj(team.getUserId(), Math.abs(bgje), bgje > 0D, entity.getYy(), request);
            footZnxService.sendZnx(footUserService.getAdminUserid(), team.getUserId(),
                    entity.getYy(), null, null, request);
        }
        return super.updateNotNull(team, request);
    }

    /**
     * 更新非空字段
     *
     * @param entity  实体类
     * @param request 请求
     * @return 是否成功
     */
    @Override
    @Transactional
    public int update(FootTeam entity, HttpServletRequest request) {
        return super.updateNotNull(entity, request);
    }

    /**
     * 根据用户id找team
     *
     * @param userId 用户主键
     * @return 球队信息
     */
    @Override
    public FootTeam getTeamByUserid(Long userId) {
        return footTeamMapper.findByUserId(userId);
    }

    /**
     * 找出赛季常规赛的前top - buttom名
     *
     * @param sjid   赛季编码
     * @param top    第一
     * @param buttom 最后
     * @return 球队列表
     */
    @Override
    public List<FootTeam> findTopClub(Long sjid, Integer top, Integer buttom) {
        List<FootClub> list = footClubService.findTopClub(sjid, top, buttom);
        List<FootTeam> teams = new ArrayList<>();
        if (list != null && !list.isEmpty()) {
            for (FootClub club : list) {
                teams.add(this.getTeamByUserid(club.getUserId()));
            }
        }
        return teams;
    }

    /**
     * 是否破产
     *
     * @param request 请求
     */
    @Override
    @Transactional
    public void isPc(HttpServletRequest request) {
        Example example = new Example(FootTeam.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLessThan("qdZzj", 0D);
        criteria.andEqualTo("delFlag", 0);
        List<FootTeam> list = this.findall(example);
        if (list == null || list.isEmpty()) {
            return;
        }
        for (FootTeam ft : list) {
            List<FootPerson> fplist = footUserPersonService.findFootPersonByUserId(ft.getUserId(), request);
            double result = ft.getQdZzj();
            //解约最贵球员,并返回80%身价
            if (result <= 0) {
                processNoMoney(result, fplist, ft, request);
            }
        }
    }

    /**
     * 锁定用户不让登陆
     *
     * @param result  结果
     * @param team    team实体类
     * @param request 请求
     */
    private void lockUser(double result, FootTeam team, HttpServletRequest request) {
        //锁定用户不让登陆
        if (result < 0) {
            FootUser user = footUserService.get(team.getUserId());
            user.setSd(true);
            footUserService.updateNotNull(user, request);
        } else {
            FootUser user = footUserService.get(team.getUserId());
            user.setSd(false);
            footUserService.updateNotNull(user, request);
        }
    }

    /**
     * 处理没有钱的问题
     *
     * @param result  结果
     * @param fplist  球员列表
     * @param team    team实体类
     * @param request 请求
     */
    private void processNoMoney(double result, List<FootPerson> fplist, FootTeam team, HttpServletRequest request) {
        lockUser(result, team, request);
        //解约最贵球员,并返回80%身价
        Double totalMoney = 0D;
        for (FootPerson fp : fplist) {
            footUserPersonService.deletePersonFromMyTeam(team.getUserId(), fp.getId(), null, request);
            totalMoney = result + Double.valueOf(fp.getQysj()) * 0.8D;
            if (totalMoney >= 0) {
                break;
            }
        }
        team.setQdZzj(team.getQdZzj() + totalMoney);
        team.setYy("由于球队无法支持继续比赛，所以解约部分球员获得资金" + totalMoney + "PB,当前球队的总资金为:" + team.getQdZzj() + "PB");
        this.updateNotNull(team, request);
        lockUser(totalMoney, team, request);
    }

    /**
     * 发奖励
     *
     * @param sj      赛季
     * @param isRank  是否排名
     * @param request 请求
     */
    @Override
    public void fjl(Long sj, boolean isRank, HttpServletRequest request) {
        /*  赛季奖金发放
         * 	明日之星		胜率>=20%		10	绿色碎片1个
         *	初露锋芒		胜率>=50%		10	绿色碎片3个
         *	领头羊		胜率>=80%		20	蓝色碎片3个
         *	灵敏嗅觉		进球>=50个		10	蓝色碎片3个
         *	百发百中		进球>=100个		20	蓝色碎片6个
         *	固若金汤		失球总数最少		20	紫色碎片3个
         *	无坚不摧		进球总数最多		20	紫色碎片3个
         *	铁人			场次达到30场		20	蓝色碎片3个   紫色碎片1个
         *	巅峰之战		常规赛冠军		30	紫色碎片*3
         *	差之毫厘		常规赛亚军		20	紫色碎片*2
         *	再接再厉		常规赛季军		10	紫色碎片*1
         *	大满贯		进球最多，失球最少	50	紫色碎片3个 橙色碎片2个
         *	宇宙第一		完成所有赛季任务	100	紫色碎片5个  橙色碎片3个
         */
        if (isRank) {
            //排位赛前三名
            processTop3Win(request);
        } else {
            //明日之星
            processStar(sj, request);
            //初露锋芒
            processFirst(sj, request);
            //领头羊
            processTopSheep(sj, request);
            //灵敏嗅觉
            processSmell(sj, request);
            //百发百中
            processMadeIt(sj, request);
            //固若金汤
            processDefenceTop(sj, request);
            //无坚不摧
            processAttackTop(sj, request);
            //铁人
            processIronMan(sj, request);
            //巅峰之战 1-3
            processTop1(request);
            processTop2(request);
            processTop3(request);
            //宇宙第一
            processAlwaysFirst(request);
        }
    }

    /**
     * 处理前三名奖励
     *
     * @param request 请求
     */
    private void processTop3Win(HttpServletRequest request) {
        //排位赛前三名
        List<FootRank> list = footRankService.getScoreboard();
        if (list != null && list.size() > 3) {
            this.getRankEndMoney(list.get(0), "冠军", 30, request);
            this.getRankEndMoney(list.get(1), "亚军", 20, request);
            this.getRankEndMoney(list.get(2), "季军", 10, request);
        }
    }

    /**
     * 处理明日之星奖励
     *
     * @param sjId    赛季主键
     * @param request 请求
     */
    private void processStar(Long sjId, HttpServletRequest request) {
        List<FootClub> list = footClubService.getWinClubsBySj(4, sjId);
        for (FootClub club : list) {
            temp.add(club);
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 10D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHaveGreen(chip.getHaveGreen() + 1L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成明日之星任务,获得奖励：10PB 绿色碎片1个 ");
            this.updateNotNull(team, request);
        }
    }

    /**
     * 处理初露锋芒奖励
     *
     * @param sjId    赛季主键
     * @param request 请求
     */
    private void processFirst(Long sjId, HttpServletRequest request) {
        List<FootClub> list2 = footClubService.getWinClubsBySj(5, sjId);
        for (FootClub club : list2) {
            if (temp.contains(club)) {
                alllist.add(club);
            }
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 10D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHaveGreen(chip.getHaveGreen() + 3L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成初露锋芒任务,获得奖励：10PB 绿色碎片3个 ");
            this.updateNotNull(team, request);
        }
        temp.clear();
        temp = alllist;
        alllist.clear();
    }

    /**
     * 处理领头羊奖励
     *
     * @param sjId    赛季主键
     * @param request 请求
     */
    private void processTopSheep(Long sjId, HttpServletRequest request) {
        List<FootClub> list3 = footClubService.getWinClubsBySj(6, sjId);
        for (FootClub club : list3) {
            if (temp.contains(club)) {
                alllist.add(club);
            }
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 20D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHaveBlue(chip.getHaveBlue() + 3L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成领头羊任务,获得奖励：20PB 蓝色碎片3个");
            this.updateNotNull(team, request);
        }
        temp.clear();
        temp = alllist;
        alllist.clear();
    }

    /**
     * 处理灵敏嗅觉奖励
     *
     * @param sjId    赛季主键
     * @param request 请求
     */
    private void processSmell(Long sjId, HttpServletRequest request) {
        List<FootClub> list4 = footClubService.getWinClubsBySj(7, sjId);
        for (FootClub club : list4) {
            if (temp.contains(club)) {
                alllist.add(club);
            }
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 10D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHaveBlue(chip.getHaveBlue() + 3L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成灵敏嗅觉任务,获得奖励：10PB 蓝色碎片3个");
            this.updateNotNull(team, request);
        }
        temp.clear();
        temp = alllist;
        alllist.clear();
    }

    /**
     * 处理百发百中奖励
     *
     * @param sjId    赛季主键
     * @param request 请求
     */
    private void processMadeIt(Long sjId, HttpServletRequest request) {
        List<FootClub> list5 = footClubService.getWinClubsBySj(8, sjId);
        for (FootClub club : list5) {
            if (temp.contains(club)) {
                alllist.add(club);
            }
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 20D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHaveBlue(chip.getHaveBlue() + 6L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成百发百中任务,获得奖励：20PB 蓝色碎片6个 ");
            this.updateNotNull(team, request);
        }
        temp.clear();
        temp = alllist;
        alllist.clear();
    }

    /**
     * 处理固若金汤奖励
     *
     * @param sjId    赛季主键
     * @param request 请求
     */
    private void processDefenceTop(Long sjId, HttpServletRequest request) {
        List<FootClub> list6 = footClubService.getWinClubsBySj(1, sjId);
        if (list6 != null && !list6.isEmpty()) {
            FootClub club = list6.get(0);
            if (temp.contains(club)) {
                alllist.add(club);
            }
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 20D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHavePurple(chip.getHavePurple() + 3L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成固若金汤任务,获得奖励：20PB 紫色碎片3个 ");
            this.updateNotNull(team, request);
        }
        temp.clear();
        temp = alllist;
        alllist.clear();
    }

    /**
     * 处理无坚不摧奖励
     *
     * @param sjId    赛季主键
     * @param request 请求
     */
    private void processAttackTop(Long sjId, HttpServletRequest request) {
        List<FootClub> list7 = footClubService.getWinClubsBySj(2, sjId);
        if (list7 != null && !list7.isEmpty()) {
            FootClub club = list7.get(0);
            if (temp.contains(club)) {
                alllist.add(club);
            }
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 20D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHavePurple(chip.getHavePurple() + 3L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成无坚不摧任务,获得奖励：20PB 紫色碎片3个 ");
            this.updateNotNull(team, request);
        }
        temp.clear();
        temp = alllist;
        alllist.clear();
    }

    /**
     * 处理铁人奖励
     *
     * @param sjId    赛季主键
     * @param request 请求
     */
    private void processIronMan(Long sjId, HttpServletRequest request) {
        List<FootClub> list8 = footClubService.getWinClubsBySj(3, sjId);
        for (FootClub club : list8) {
            if (temp.contains(club)) {
                alllist.add(club);
            }
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 20D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHaveBlue(chip.getHaveBlue() + 3L);
                chip.setHavePurple(chip.getHavePurple() + 1L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成铁人任务,获得奖励：20PB 蓝色碎片3个和紫色碎片1个 ");
            this.updateNotNull(team, request);
        }
        temp.clear();
        temp = alllist;
        alllist.clear();
    }

    /**
     * 处理巅峰之战奖励
     *
     * @param request 请求
     */
    private void processTop1(HttpServletRequest request) {
        FootClub top1 = footClubService.getTopClubBySj(1);
        if (null != top1) {
            if (temp.contains(top1)) {
                alllist.add(top1);
            }
            FootTeam top1team = this.getTeamByUserid(top1.getUserId());
            top1team.setQdZzj(top1team.getQdZzj() + 30D);
            FootChip top1chip = footChipService.findChipByUserId(top1.getUserId());
            if (null != top1chip) {
                top1chip.setHavePurple(top1chip.getHavePurple() + 3L);
                footChipService.updateNotNull(top1chip, request);
            }
            top1team.setYy("完成巅峰之战任务,获得奖励：30PB 紫色碎片3个 ");
            this.updateNotNull(top1team, request);
        }
        temp.clear();
        alllist.clear();
    }

    /**
     * 处理差之毫厘奖励
     *
     * @param request 请求
     */
    private void processTop2(HttpServletRequest request) {
        FootClub top2 = footClubService.getTopClubBySj(2);
        if (null != top2) {
            FootTeam top2team = this.getTeamByUserid(top2.getUserId());
            top2team.setQdZzj(top2team.getQdZzj() + 20D);
            FootChip top2chip = footChipService.findChipByUserId(top2.getUserId());
            if (null != top2chip) {
                top2chip.setHavePurple(top2chip.getHavePurple() + 2L);
                footChipService.updateNotNull(top2chip, request);
            }
            top2team.setYy("完成差之毫厘任务,获得奖励：20PB 紫色碎片2个 ");
            this.updateNotNull(top2team, request);
        }
    }

    /**
     * 处理再接再厉奖励
     *
     * @param request 请求
     */
    private void processTop3(HttpServletRequest request) {
        FootClub top3 = footClubService.getTopClubBySj(3);
        if (null != top3) {
            FootTeam top3team = this.getTeamByUserid(top3.getUserId());
            top3team.setQdZzj(top3team.getQdZzj() + 10D);
            FootChip top3chip = footChipService.findChipByUserId(top3.getUserId());
            if (null != top3chip) {
                top3chip.setHavePurple(top3chip.getHavePurple() + 1L);
                footChipService.updateNotNull(top3chip, request);
            }
            top3team.setYy("完成再接再厉任务,获得奖励：10PB 紫色碎片1个 ");
            this.updateNotNull(top3team, request);
        }
    }

    /**
     * 处理宇宙第一奖励
     *
     * @param request 请求
     */
    private void processAlwaysFirst(HttpServletRequest request) {
        //宇宙第一 算法
        for (FootClub club : alllist) {
            FootTeam team = this.getTeamByUserid(club.getUserId());
            team.setQdZzj(team.getQdZzj() + 100D);
            FootChip chip = footChipService.findChipByUserId(club.getUserId());
            if (null != chip) {
                chip.setHavePurple(chip.getHavePurple() + 5L);
                chip.setHaveOrange(chip.getHaveOrange() + 3L);
                footChipService.updateNotNull(chip, request);
            }
            team.setYy("完成宇宙第一任务,获得奖励：100PB 紫色碎片5个  橙色碎片3个 ");
            this.updateNotNull(team, request);
        }
    }

    /**
     * 给排位赛发奖励了
     *
     * @param footRank 排位实体
     * @param mc       名次
     * @param money    获得的奖励金额
     * @param request  请求
     */
    private void getRankEndMoney(FootRank footRank, String mc, double money, HttpServletRequest request) {
        if (footRank != null) {
            FootTeam team = this.getTeamByUserid(footRank.getUserId());
            if (null != team) {
                team.setQdZzj(team.getQdZzj() + money);
                team.setYy("获得排位赛第" + mc + "名，奖励资金：" + money + "PB");
                this.updateNotNull(team, request);
            }
        }
    }

    /**
     * 根据用户主键获取图片
     *
     * @param userId 用户主键
     * @return 图片主键
     */
    @Override
    public Long getLogoByUserid(Long userId) {
        FootTeam team = this.getTeamByUserid(userId);
        if (null != team && team.getId() != null) {
            FootQd qd = footQdService.get(team.getQdId());
            if (null != qd) {
                return qd.getLogo();
            }
        }
        return null;
    }

    /**
     * 根据用户主键获取缩略图
     *
     * @param userId 用户主键
     * @return 缩略图主键
     */
    @Override
    public Long getSltByUserid(Long userId) {
        FootTeam team = this.getTeamByUserid(userId);
        if (null != team && !StringUtils.isEmpty(team.getId())) {
            FootQd qd = footQdService.get(team.getId());
            if (null != qd) {
                return qd.getSlt();
            }
        }
        return null;
    }

    /**
     * 保存球队信息
     *
     * @param user    用户
     * @param qd      球队
     * @param request 请求
     */
    @Override
    public void saveNewTeam(FootUser user, FootQd qd, HttpServletRequest request) {
        FootTeam ft = new FootTeam();
        ft.setQdId(qd.getId());
        ft.setQdZzj(0D);
        ft.setUserId(user.getId());
        this.save(ft, request);
        //初始资金分配
        this.createZjTeamByUserId(user.getId(), qd.getId(), qd.getQdmc(), request);
    }

    /**
     * 创建球队的资金初始值
     *
     * @param userId  用户主键
     * @param qdId    球队主键
     * @param qdmc    球队名称
     * @param request 请求
     */
    @Override
    public void createZjTeamByUserId(Long userId, Long qdId, String qdmc, HttpServletRequest request) {
        FootTeam team = this.getTeamByUserid(userId);
        if (team != null) {
            if (null != qdId) {
                team.setQdId(qdId);
            }
            if (null != qdmc) {
                team.setQdName(qdmc);
            }
            team.setQdZzj(CSZJ);
            if (request != null) {
                team.setUpdateId((Long) request.getSession().getAttribute(Constants.USERID));
            } else {
                team.setUpdateId(1L);
            }
            team.setUpdateTime(new Date());
            footTeamDao.updateByPrimaryKeySelective(team);
            footZjService.sendZj(userId, CSZJ, true, "因分配球队获得常规赛初始资金" +
                    new DecimalFormat(",###").format(CSZJ) + "PB,当前球队的总资金为:" +
                    new DecimalFormat(",###").format(team.getQdZzj()) + "PB", request);
            footZnxService.sendZnx(footUserService.getAdminUserid(), userId, "已分配" + team.getQdName() +
                    "给玩家,可以继续游戏", null, null, request);
            if (request != null) {
                request.getSession().setAttribute("myTeam", team);
            }
        }
    }

    /**
     * 根据球队主键获取记录列表
     *
     * @param qdId 球队主键
     * @return 列表
     */
    @Override
    public List<FootTeam> findTeamByQdId(Long qdId) {
        Example example = new Example(FootTeam.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("qdId", qdId);
        criteria.andEqualTo("delFlag", 0);
        return this.findall(example);
    }

    /**
     * 翻页方法
     *
     * @param footTeamSearchForm 条件
     * @return 列表
     */
    @Override
    public List<FootTeam> findall(FootTeamSearchForm footTeamSearchForm) {
        return footTeamMapper.findall(footTeamSearchForm);
    }

    /**
     * 根据主键获取记录
     *
     * @param id 主键
     * @return 记录
     */
    @Override
    public FootTeam get(Serializable id) {
        return footTeamMapper.findById(id);
    }

    /**
     * 查询
     *
     * @param entityname         实体类名
     * @param map                参数
     * @param footTeamSearchForm 条件
     */
    @Override
    public void search(String entityname, Model map, FootTeamSearchForm footTeamSearchForm) {
        map.addAttribute(String.format(Constants.FORMNAME, entityname), footTeamSearchForm);
        Page<FootTeam> page = PageHelper.startPage(footTeamSearchForm.getPageIndex(), footTeamSearchForm.getPageSize());
        List<FootTeam> list = this.findall(footTeamSearchForm);
        map.addAttribute(Constants.PI, page.toPageInfo());
        map.addAttribute(String.format(Constants.LISTENTITY, entityname), list);
    }

    /**
     * 删除所有
     *
     * @param footTeamSearchForm 条件
     * @param request            请求
     */
    @Override
    public void deleteAll(FootTeamSearchForm footTeamSearchForm, HttpServletRequest request) {
        if (footTeamSearchForm.getSelectIds() != null) {
            String[] result = footTeamSearchForm.getSelectIds().split(Constants.COMMA);
            for (String id : result) {
                this.delete(Long.parseLong(id), request);
            }
        }
    }

    /**
     * 根据用户主键删除对应记录
     *
     * @param userId  用户主键
     * @param request 请求
     */
    @Override
    public void deleteByUserId(Long userId, HttpServletRequest request) {
        //删除球队
        FootTeam team = this.getTeamByUserid(userId);
        if (team != null) {
            this.delete(team.getId(), request);
        }
    }

    /**
     * 花费金额获取球员的一系列数据操作
     *  @param userId  用户主键
     * @param needPay 花费金额
     * @param fullName 球员名称
     * @param request 请求
     */
    @Override
    public void payQy(Long userId, Double needPay, String fullName, HttpServletRequest request) {
        FootTeam team = this.getTeamByUserid(userId);
        if (team == null) {
            return;
        }
        Double bgje = team.getQdZzj() - needPay;
        team.setQdZzj(bgje);
        team.setYy("抽奖花费" + needPay + "PB，获取球员" + fullName);
        footZjService.sendZj(team.getUserId(), Math.abs(bgje), bgje > 0D, team.getYy(), request);
        footZnxService.sendZnx(footUserService.getAdminUserid(), team.getUserId(),
                team.getYy(), null, null, request);
        super.updateNotNull(team, request);
    }
}
